﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DFXEditorApp
{
    public partial class EditorApp : Form
    {
        private MessageHandler messageHandler;

        public MessageHandler MessageHandler
        {
            get
            {
                return messageHandler;
            }
        }

        public EditorApp()
        {
            InitializeComponent();

            try
            {
                if (NativeMethods.EditorMain(topPanel.Handle, topPanel.Width, topPanel.Height,
                    leftPanel.Handle, leftPanel.Width, leftPanel.Height,
                    rightPanel.Handle, rightPanel.Width, rightPanel.Height,
                    perspPanel.Handle, perspPanel.Width, perspPanel.Height) != 0)
                {
                    MessageBox.Show("Unable to initialize editor", "Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }

                messageHandler = new MessageHandler(Handle, topPanel.Handle, this);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void Shutdown()
        {
            try
            {
                NativeMethods.EditorDestroy();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void EditorApp_FormClosed(object sender, FormClosedEventArgs e)
        {
            Shutdown();
        }
    }
}
